{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9772f3c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "init\n",
      "enter\n",
      "type: None\n",
      "value: None\n",
      "trace: None\n"
     ]
    }
   ],
   "source": [
    "class Sample:\n",
    "    def __init__(self):\n",
    "        print(\"init\")\n",
    "        self.rate = 0\n",
    "    def __enter__(self):\n",
    "        print(\"enter\")\n",
    "        self.rate += 1\n",
    "        return self\n",
    "\n",
    "    def __exit__(self, type, value, trace):\n",
    "        print(\"type:\", type)\n",
    "        print(\"value:\", value)\n",
    "        print(\"trace:\", trace)\n",
    "\n",
    "    def do_something(self):\n",
    "        import numbers\n",
    "        assert(isinstance(self.rate, numbers.Number) and self.rate != 0)\n",
    "        del numbers\n",
    "        bar = 10\n",
    "        return bar/self.rate\n",
    "\n",
    "with Sample() as sample:\n",
    "    sample.do_something()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b0099ae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
